import os

def combine_1():
    dict_dir="/Users/mac/Documents/sean_pj/dict/ansj/dict/"
    saving_path="/Users/mac/Documents/sean_pj/dict/ansj/combined_default.dic"
    cnt=0
    with open(saving_path,'w') as comb:
        for dir_path,dirs,files in os.walk(dict_dir):
            for f in files:
                if (f.find('.dic')<0):
                    continue
                print(f)
                with open(dir_path+'/'+f) as dict_file:
                    line = dict_file.readline()
                    # line.decode("utf8", "ignore")
                    # print(line)
                    while line:
                        tmp=line.strip()
                        tmp=clean(tmp)
                        comb.write(tmp)
                        comb.write('\n')
                        cnt+=1
                        line = dict_file.readline()
    print(cnt)


def clean(title):
    title = title.lower()
    if title.find(':') > 0:
        title = title.split(':')[1]
    if title.find('(') > 0:
        title = title.split('(')[0]
    if title.find('|') > 0:
        title = title.split('|')[0]
    return title



if __name__ == '__main__':
    combine_1()